import axios from "axios"
// import useSWR from 'swr'
import { useCallback, useEffect, useState } from "react"
import Image from "next/image"
import Script from "next/script"
const Profile = ({data})=>{
    const [user,setUser] = useState(data)
    const getData = useCallback(async ()=>{
        const resdata = await axios.get('http://www.web2.com/dataapi/data.php?id=2');
        const res = resdata.data;
        if(res.code == 1){
            setUser(res.data)
        }
        
        
    },[])
    return (
        <div>
            <div>{user.name}</div>
            <button onClick={getData}>获取新的数据</button>
            <div>
                <Image
                    src="https://res.ddddyres.com//uploads/avatar/20190926/03yxr57qaj2p647snupjp3mdh2o2kfsr.jpg"
                    width={300}
                    height={300}
                    className="shun"
                    alt="用户图像"
                />
            </div>
            <div style={{width:300,height:300,position:'relative'}}>
                <Image
                    src="https://res.sharkerr.com/uploads/photo/20230206/5eaf3a828acbe7834e302840da28d8a2.jpeg"
                    layout='fill'
                    alt="用户图像"
                />

            </div>
            <Script src="https://res.alpha.daofengdj.com/static/plugins/jquery-2.2.3.min.js" />
        </div>
    )
}
export async function getServerSideProps(context){
    const res = await axios({
        method: 'get',
        url: 'http://www.web2.com/dataapi/data.php',
        params: { id: context.params.id },
    })
    if(!res.data.data.name){
        return {
            redirect:{
                destination: '/',
                permanent: false,
            }
        }
    }
    return {
        props:{
            data:res.data.data
        }
    }
}
export default Profile